<template>
	<view class="wrapper">
		<Head color="#fff" title="积分充值" type="detail" backgroundColor="transparent" leftIcon="left" :border="false">
		</Head>
		<view class="inner">
			<image class="innerImage" src="@/service/static/img/integralBg.png"></image>
			<view class="number">
				<view class="t1">{{member_points}}</view>
				<view class="t2">我的积分</view>
			</view>

			<view class="integral">
				<view class="title">选择充值套餐</view>
				<view class="integralNumList">
					<view :class="index == listIndex ? 'integralNum ac' : 'integralNum'"
						v-for="(item,index) in pointsList" @click="handleIntegral(item,index)">
						<view class="recommend" v-if="item.recommend == 1">
							<image src="@/service/static/img/recommend.png"></image>
						</view>
						<view class="t1 substring">{{item.name}}</view>
						<view class="t2">
							<text>￥</text>
							<text>{{item.expense1}}.{{item.expense2}}</text>
						</view>
					</view>
				</view>
			</view>

			<view class="splitLine"></view>


			<radio-group @change="handleChangePaymentType">
				<label>
					<view class="payLine wxIcon">
						<view class="label">微信支付</view>
						<view class="text">
							<radio value="wxpay" :checked="paymentType == 'wxpay'" />
						</view>
					</view>
				</label>
				<!-- #ifdef APP-PLUS -->
				<label>
					<view class="payLine aliIcon">
						<view class="label">支付宝支付</view>
						<view class="text">
							<radio value="alipay" :checked="paymentType == 'alipay'" />
						</view>
					</view>
				</label>
				<!-- #endif -->
			</radio-group>
			<view class="btns">
				<view class="price">
					<text class="color1">应付金额：</text><text class="color2">￥{{amount}}</text>
				</view>
				<view class="btn">
					<Pay :paymentType="paymentType" :orderParams="params" @handlePaySuccess="handlePaySuccess"
						@handlePayFail="handlePayFail">立即支付</Pay>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import handlerHttpError from '@/utils/error';
	import http from '@/utils/http';
	import api from '@/api';
	export default {
		data() {
			return {
				// 支付类型
				paymentType: 'wxpay',
				// 积分数量
				member_points: 0,
				// 积分套餐列表
				pointsList: [],
				// 当前选择积分下标
				listIndex: 0,
				// 购买积分参数
				params: {
					payment: 'wxpay',
					service_id: 0,
					service_type: 'points'
				},
				// 金额数
				amount: 0
			};
		},
		created() {
			this.getPointsList()
		},
		methods: {
			// 支付切换
			handleChangePaymentType(e) {
				this.paymentType = e.detail.value
				this.params.payment = e.detail.value
			},
			// 获取积分列表
			getPointsList() {
				http.get(api.points_setmeal_list).then(response => {
					let res = response.data
					if (res.code == 200) {
						let list = res.data.items
						this.member_points = res.data.member_points
						this.amount = list[0].expense
						this.params.service_id = list[0].id
						for (const iterator of list) {
							let expense_arr = iterator.expense.split('.')
							iterator.expense1 = expense_arr[0]
							iterator.expense2 = expense_arr[1]
							this.pointsList.push(iterator)
						}
					}
					console.log(this.pointsList, 'this.pointsList')
				})
			},
			// 积分套餐点击
			handleIntegral(item, index) {
				this.listIndex = index
				this.amount = item.expense
				this.params.service_id = item.id
			},
			// 支付成功
			handlePaySuccess() {
				uni.navigateTo({
					url: '/commonViews/service/OrderList'
				})
			},
			// 支付失败
			handlePayFail() {
				uni.navigateTo({
					url: '/commonViews/service/OrderList'
				})
			}
		},
	}
</script>

<style lang="scss" scoped>
	.wrapper {
		width: 100%;
		height: 100%;
		// background: url("@/service/static/img/integralBg.png") no-repeat top /100% auto;

		.inner {
			position: relative;
			height: calc(100% - 140rpx);
			position: relative;

			.innerImage {
				display: block;
				width: 100%;
				height: 396rpx;
			}

			.number {
				color: #fff;
				padding: 64rpx 0 88rpx 50rpx;
				position: absolute;
				top: 85rpx;

				.t1 {
					font-size: 50rpx;
					margin-bottom: 20rpx;
				}

				.t2 {
					font-size: 28rpx;
				}
			}

			.integral {
				border-radius: 40rpx 40rpx 0 0;
				background: #fff;
				padding-bottom: 60rpx;
				margin-top: -40rpx;

				.title {
					padding: 50rpx 36rpx;
					color: #333;
					font-size: 32rpx;
					font-weight: bold;
				}

				.integralNumList {
					white-space: nowrap;
					overflow-y: auto;
					margin: 0 0 0 36rpx;

					.integralNum {
						display: inline-block;
						width: 234rpx;
						height: 180rpx;
						margin-right: 30rpx;
						background: #FFFBF4;
						border: 1rpx solid #E3A03A;
						border-radius: 26rpx;
						text-align: center;
						box-sizing: border-box;
						position: relative;

						.recommend {
							width: 60rpx;
							height: 60rpx;
							position: absolute;
							left: 0;
							top: 0;
							display: none;

							image {
								width: 100%;
								height: 100%;
							}
						}

						.t1 {
							color: #333;
							font-size: 28rpx;
							height: 110rpx;
							line-height: 110rpx;
						}

						.t2 {
							height: 70rpx;
							line-height: 70rpx;
							color: #8D5602;
							font-size: 28rpx;
							font-weight: bold;
							border-radius: 0 0 24rpx 24rpx;
							background: rgba(227, 160, 58, .2);
						}

						&:last-child {
							margin-right: 0;
						}

						&.ac {
							border: 1rpx solid #FD6260;

							.t2 {
								background: #FD6260;
								color: #fff;
							}
						}
					}
				}
			}


			.payLine {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 36rpx 0;
				margin: 0 36rpx;

				&.wxIcon {
					padding-left: 60rpx;
					background: url('@/service/static/img/wxPayIcon3.png') no-repeat left center /46rpx 40rpx;
				}

				&.aliIcon {
					padding-left: 60rpx;
					background: url('@/service/static/img/aliPayIcon.png') no-repeat left center /46rpx 46rpx;
				}

				&.border {
					border-bottom: 1rpx solid #ededed;
				}

				.label {
					color: #333;
					font-size: 28rpx;
				}

				.text {
					color: #333;
					font-size: 28rpx;
					display: flex;
					align-items: center;

					.color {
						color: #999;
					}
				}
			}

		}

		.btns {
			position: absolute;
			left: 0;
			right: 0;
			bottom: 0;
			padding: 30rpx 36rpx;
			background-color: #fff;
			display: flex;
			justify-content: space-between;
			align-items: center;
			border-top: 1rpx solid #ededed;

			.btn {
				flex-shrink: 0;
				color: #FFFFFF;
				font-size: 28rpx;
				background: #FD6260;
				padding: 15rpx 30rpx;
				border-radius: 10rpx;
			}

			.price {
				font-size: 28rpx;

				.color1 {
					color: #010000;
				}

				.color2 {
					color: #FF4030;
				}
			}
		}
	}
</style>